package leetcode

type ListNode struct {
	Val  int
	Next *ListNode
}

func deleteDuplicates(head *ListNode) *ListNode {
	resHead := ListNode{0, nil}
	tailPtr := &resHead
	for head != nil {
		if head.Next != nil && head.Val == head.Next.Val {
			dupVal := head.Val
			for head != nil && head.Val == dupVal {
				head = head.Next
			}
		} else {
			tailPtr.Next = head
			tailPtr = tailPtr.Next
			head = head.Next
		}
	}
	tailPtr.Next = nil
	return resHead.Next
}
